<?php
/**
 * User: 五哥派
 * Date: 2024/6/30
 * Tel(同WX): 17335592719
 */
namespace app\admin\service;

use app\admin\model\store\GoodsSku as GoodsSkuModel;

class GoodsSku extends BaseService{

    public $model = NULL;

    public function __construct(){
        $this->model = new GoodsSkuModel();
    }

    /**
     * 批量新增逻辑
     */
    public function saveAll($data) {
        if(!$data['skus']) {
            return false;
        }

        foreach($data['skus'] as $value) {
            $insertData[] = [
                "goods_id" => $data['goods_id'],
                "category_id" => $data['category_id'],
                "specs_value_ids" => $value['propvalnames']['propvalids'],
                "sell_price" => $value['propvalnames']['skuSellPrice'],
                "market_price" => $value['propvalnames']['skuMarketPrice'],
                "stock" => $value['propvalnames']['skuStock'],
                "status" => 1,
            ];
        }

        try {
            $result = $this->model->saveAll($insertData);
            return $result->toArray();
        }catch (\Exception $e) {
            ///echo $e->getMessage();exit;
            // 记录日志
            return false;
        }
    }

}